package com.sunxueqi.project.log.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.log.service.IVisitLogService;
import com.sunxueqi.project.log.vo.VisitLog;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;

@Api(tags="访问日志")
@RestController
@RequestMapping("/log/visitLog")
public class VisitLogController extends BaseController{
	@Autowired
	private IVisitLogService visitLogService;
	
	/**
	 * 获取操作日志列表
	 * @param visitLog
	 * @return
	 */
	@GetMapping("/list")
	public ResponseData list(VisitLog visitLog) {
		startPage();
		List<VisitLog> list = visitLogService.selectVisitLogList(visitLog);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 删除操作日志
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public ResponseData delete(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(visitLogService.deleteVisitLogByIds(idArray));
	}
	
	/**
	 * 清除所有登录日志
	 * @return
	 */
	@DeleteMapping("/clean")
	public ResponseData cleanLog() {
		visitLogService.cleanLog();
		return ResponseData.success();
	}
}
